home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / utils / stripdupe / stripdupe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  1.1 KB  |  57 lines

  1. #include <exec/exec.h>
  2. #include <stdio.h>
  3. char FileName[200];
  4. char Destination[200];
  5. void sr(char *s);
  6. main(int argc,char *argv[])
  7. {
  8.   FILE *fi,*fo;
  9.   char image[200];
  10.   char dupe[200];
  11.   if(argc!=2)
  12.   {
  13.     printf("StripDupe, version1.0 written by Joseph Hodge\n");
  14.     printf("usage: StripDupe <filename>\n");
  15.     printf("\n");
  16.     exit(0);
  17.   }
  18.   strcpy(FileName,argv[1]);
  19.   sr(FileName);
  20.   strcpy(Destination,FileName);
  21.   strcat(Destination,"{temp}");
  22.   if(!access(Destination,00))
  23.   {
  24.     DeleteFile(Destination);
  25.   }
  26.   if(access(FileName,00))
  27.   {
  28.     printf("File %s does not exist\n",FileName);
  29.     exit(0);
  30.   }
  31.   Rename(FileName,Destination);
  32.   fi=fopen(Destination,"r");
  33.   strcpy(dupe,"");
  34.   fo=fopen(FileName,"w");
  35.   while(fgets(image,190,fi)!=NULL)
  36.   {
  37.     sr(image);
  38.     if(strcmp(image,dupe)) fprintf(fo,"%s\n",image);
  39.     else printf("Removing %70.70s\n",image);
  40.     strcpy(dupe,image);
  41.   }
  42.   fclose(fi);
  43.   fclose(fo);
  44.   DeleteFile(Destination);
  45.   exit(0);
  46. }
  47.  
  48. void sr(char *s)
  49. {
  50.   register int i;
  51.   i=strlen(s)-1;
  52.   while(i>-1)
  53.   {
  54.     if(*(s+i)<=32) *(s+i)='\0'; else break;
  55.     i--;
  56.   }
  57. }